package com.faiz.algorithm;

public class ReorderList {

    public static ListNode p;

    public static void reorder(ListNode pre, ListNode head) {
        if (head == null) return;

        reorder(head, head.next);
        // 针对点的数量为偶数或是奇数时
        if (p.next == head || p.next == null) return;

        head.next = p.next;
        pre.next = null;
        p.next = head;
        p = p.next.next;
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        head.next = new ListNode(2);
        head.next.next = new ListNode(3);
        head.next.next.next = new ListNode(4);

        p = head;

        reorder(head, head.next);
    }
}
